# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=mono-basic
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.6
pkgrel=1
pkgdesc="Mono Visual Basic.NET compiler (mingw-w64)"
arch=('any')
url="http://www.mono-project.com/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-mono")
source=("${_realname}-${pkgver}.tar.xz"::"http://download.mono-project.com/sources/${_realname}/${_realname}-${pkgver}.tar.bz2"
        "0001-mono-basic-4.6-fix-slash-vs-hyphen.patch")
sha256sums=('303d79f73ae9d6120ef12ebeaf2ec67fda96256801e3bf305c46f8787a751e8f'
            '5fa7bde4d52d262215b3bcf36ea4d23b879564b58c8fb48bab7f7186dd58e360')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-mono-basic-4.6-fix-slash-vs-hyphen.patch"
}

build() {
  # get rid of that .wapi errors
  export MONO_SHARED_DIR="${srcdir}/weird-${CARCH}"
  mkdir -p "${MONO_SHARED_DIR}"
  
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  cp -R "${srcdir}"/${_realname}-${pkgver}/. "${srcdir}"/build-${CARCH}
  CC=${MINGW_PREFIX}/bin/gcc.exe \
  CSC=${MINGW_PREFIX}/bin/mcs \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install
  
  sed -e "s|/sdkpath|-sdkpath|g" -i "${pkgdir}${MINGW_PREFIX}/bin/vbnc2"
}
